package com.sc.nft.config;

import com.sc.nft.config.sand.CertUtil;
import com.sc.nft.config.sand.SDKConfig;
import com.sc.nft.config.sand.SandConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class SandPaySdkInitConfig {

    @Value("${pay.sandConfig.mall_notify_url}")
    private String MALL_NOTIFY_URL;

    @Value("${pay.sandConfig.mall_refund_notify_url}")
    private String MALL_REFUND_NOTIFY_URL;

    @Bean
    public void sandInitialized() {

        // 加载证书
        try {
            //加载配置文件
            SDKConfig.getConfig().loadPropertiesFromSrc();
            //加载证书
            CertUtil.init(SDKConfig.getConfig().getSandCertPath(), SDKConfig.getConfig().getSignCertPath(), SDKConfig.getConfig().getSignCertPwd());

            SandConfig.MALL_NOTIFY_URL = MALL_NOTIFY_URL;
            SandConfig.MALL_REFUND_NOTIFY_URL = MALL_REFUND_NOTIFY_URL;
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
